package com.itlong.cloud.controller.expenses;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.POJO.DTO.common.PadFaceSyncDataDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyAccountGetDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.app.AppUserAndRoomInfoVO;
import com.itlong.cloud.POJO.VO.operate.OperatePropertyAccountDetailVO;
import com.itlong.cloud.POJO.VO.property.PropertyAccountDetailVO;
import com.itlong.cloud.POJO.VO.property.PropertyPaymentVO;
import com.itlong.cloud.POJO.VO.property.PropertyUnpaymentVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.enumerate.BillTypeEnum;
import com.itlong.cloud.enumerate.FileCatalogEnum;
import com.itlong.cloud.enumerate.OriginPayEnum;
import com.itlong.cloud.enumerate.PaymentTypeEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.PropertyErrorCodeEnum;
import com.itlong.cloud.equip.property.IPadFaceSyncDataServiceClient;
import com.itlong.cloud.iottp.IIotTpJPushClientServiceClient;
import com.itlong.cloud.iottp.IIotTpSmsServiceClient;
import com.itlong.cloud.project.property.IPropertyAccountServiceClient;
import com.itlong.cloud.project.property.IPropertyRuleServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.operate.IOperatePropertyAccountServiceClient;
import com.itlong.cloud.user.property.IPropertyUserServiceClient;
import com.itlong.cloud.utils.file.UploadFileUtil;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.URLEncoder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <desc>
 *      物业系统收费管理物业账单模块聚合Controller。
 * </desc>
 * @createDate 2018/08/13
 */
@RestController
@RequestMapping(path = "/expenses/account")
@RefreshScope
public class PropertyAccountController extends BaseController {

    private static Logger LOG = LoggerFactory.getLogger(PropertyAccountController.class);

    @Value("${" + PlatformConstants.FILE_FTP_HOST + "}")
    public String FILE_FTP_HOST;

    @Value("${" + PlatformConstants.FILE_FTP_PORT + "}")
    public String FILE_FTP_PORT;

    @Value("${" + PlatformConstants.FILE_FTP_USERNAME + "}")
    public String FILE_FTP_USERNAME;

    @Value("${" + PlatformConstants.FILE_FTP_PASSWORD + "}")
    public String FILE_FTP_PASSWORD;

    @Value("${" + PlatformConstants.FILE_ACCESS_URL + "}")
    public String FILE_ACCESS_URL;

    @Value("${" + PlatformConstants.PROJECT_STATIC_FILE_PATH + "}")
    public String PROJECT_STATIC_FILE_PATH;

    @Autowired
    IPropertyAccountServiceClient iPropertyAccountServiceClient;

    @Autowired
    IIotTpSmsServiceClient iIotTpSmsServiceClient;

    @Autowired
    IPropertyUserServiceClient iPropertyUserServiceClient;

    @Autowired
    IOperatePropertyAccountServiceClient iOperatePropertyAccountServiceClient;

    @Autowired
    IPropertyRuleServiceClient iPropertyRuleServiceClient;

    @Autowired
    private IIotTpJPushClientServiceClient iIotTpJPushClientServiceClient;

    @Autowired
    private IPadFaceSyncDataServiceClient iPadFaceSyncDataServiceClient;


    /**
     * <desc>
     *      分页查询未缴账单
     * <desc/>
     *
     * @param propertyAccountGetDTO 查询未缴费数据
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/13
     */
    @ResponseBody
    @RequestMapping(path = "getUnpaymentByPage", method = RequestMethod.POST)
    public Object getUnpaymentByPage(PropertyAccountGetDTO propertyAccountGetDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyAccountGetDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyAccountGetDTO.class, request);
            if(StringUtils.isBlank(propertyAccountGetDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            Page<PropertyUnpaymentVO> result =
                    iPropertyAccountServiceClient.getUnpaymentByPage(propertyAccountGetDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), result);
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_收费管理_查询未缴费信息】查询未缴费信息失败"), e);
        }
    }

    /**
     * <desc>
     *      分页查询已缴账单
     * <desc/>
     *
     * @param propertyAccountGetDTO 查询已缴费数据
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/13
     */
    @ResponseBody
    @RequestMapping(path = "/getPaymentByPage", method = RequestMethod.POST)
    public Object getPaymentByPage(PropertyAccountGetDTO propertyAccountGetDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyAccountGetDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyAccountGetDTO.class, request);
            if(StringUtils.isBlank(propertyAccountGetDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            Page<PropertyPaymentVO> result =
                    iPropertyAccountServiceClient.getPaymentByPage(propertyAccountGetDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), result);
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_收费管理_查询已缴费信息】查询已缴费信息失败"), e);
        }
    }

    /**
     * <desc>
     *      导出未缴费账单
     * <desc/>
     *
     * @param propertyAccountGetDTO 查询条件
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/13
     */
    @ResponseBody
    @AuthAccessRequired
    @RequestMapping(path = "/exportUnpayment", method = RequestMethod.POST)
    public Object exportUnpayment(PropertyAccountGetDTO propertyAccountGetDTO) {
            try {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                propertyAccountGetDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyAccountGetDTO.class, request);
                if(StringUtils.isBlank(propertyAccountGetDTO.getProjectId())) {
                    return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
                }
                Path excelFilePath = Paths.get(PROJECT_STATIC_FILE_PATH, PlatformConstants.UNPAYMENT_EXPORT_EXPORT_FILE);
                if (!new File(excelFilePath.toString()).exists()) {  //模板文件不存在
                    return new MessageVO(PropertyErrorCodeEnum.PROJECT_TMPLATE_FILE_PATH_NOT_EXISTS_ERR.getErrorCode());
                }
                List<PropertyUnpaymentVO> result =
                        iPropertyAccountServiceClient.getUnpaymentByFeeIds(propertyAccountGetDTO);

                //创建Excel操作对象，07之前版本(*.xls)使用HSSFWorkBook 07之后版本使用（*.xlsx）XSSFWorkbook
                try (InputStream excelFileStream = new FileInputStream(excelFilePath.toString())) {

                    try (HSSFWorkbook workbook = new HSSFWorkbook(excelFileStream)) {
                        HSSFSheet sheet = workbook.getSheetAt(0);
                        short rowHeght = 420;
                        //移除模板中可能存在的样例数据
                        for (int rowIndex = 1; rowIndex <= 3; rowIndex++) {
                            HSSFRow row = sheet.getRow(rowIndex);
                            if (row != null) {
                                rowHeght = row.getHeight();
                                sheet.removeRow(row);
                            }
                        }

                        for (int index = 0; index < result.size(); index++) {
                            PropertyUnpaymentVO propertyUnpaymentVO = result.get(index);
                            int rowIndex = index + 1; //标题行
                            HSSFRow dataRow = sheet.createRow(rowIndex);
                            dataRow.setHeight(rowHeght);
                            HSSFCell noteCell = dataRow.createCell(0);
                            noteCell.setCellValue(propertyUnpaymentVO.getFeeId());
                            noteCell = dataRow.createCell(1);
                            noteCell.setCellValue(propertyUnpaymentVO.getMonth());
                            noteCell = dataRow.createCell(2);
                            noteCell.setCellValue(propertyUnpaymentVO.getFeeNumber());
                            noteCell = dataRow.createCell(3);
                            noteCell.setCellValue(propertyUnpaymentVO.getAddress());
                            noteCell = dataRow.createCell(4);
                            noteCell.setCellValue(propertyUnpaymentVO.getRealName());
                            noteCell = dataRow.createCell(5);
                            noteCell.setCellValue(propertyUnpaymentVO.getPhoneNum());
                            noteCell = dataRow.createCell(6);
                            noteCell.setCellValue(BillTypeEnum.getDescription(Integer.parseInt(propertyUnpaymentVO.getType())));
                            noteCell = dataRow.createCell(7);
                            noteCell.setCellValue(propertyUnpaymentVO.getDueAmount());
                            noteCell = dataRow.createCell(8);
                            noteCell.setCellValue(propertyUnpaymentVO.getPenalty());
                            noteCell = dataRow.createCell(9);
                            noteCell.setCellValue(propertyUnpaymentVO.getPaidAmount());
                            noteCell = dataRow.createCell(10);
                            noteCell.setCellValue("0".equals(propertyUnpaymentVO.getPaymentCount())?"":propertyUnpaymentVO.getPaymentCount());
                            noteCell = dataRow.createCell(11);
                            noteCell.setCellValue(propertyUnpaymentVO.getCreateTime());
                        }
                        String fileName = String.format("%s_UnpaymentInfo_%s.xls",
                                propertyAccountGetDTO.getProjectId(),
                                DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS"));
                        fileName = URLEncoder.encode(fileName, "UTF-8");

                        ByteArrayOutputStream os = new ByteArrayOutputStream();
                        workbook.write(os);
                        byte[] content = os.toByteArray();
                        InputStream exportFileStream = new ByteArrayInputStream(content);
                        String exportfileUrl = uploadFile(exportFileStream,fileName);
                        if (StringUtils.isBlank(exportfileUrl)){
                            return new MessageVO(PropertyErrorCodeEnum.PROJECT_EXPORT_FILE_SAVE_ERR.getErrorCode());
                        }
                        return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), (Object) exportfileUrl);
                    }
                }
            } catch (Exception e) {
                throw new DataAccessException(String.format(
                        "【物业系统_收费管理_导出未缴费信息】导出未缴费信息失败"), e);
            }
    }

    /**
     * <desc>
     *      导出已缴费账单
     * <desc/>
     *
     * @param propertyAccountGetDTO 查询条件
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/14
     */
    @ResponseBody
    @AuthAccessRequired
    @RequestMapping(path = "/exportPayment", method = RequestMethod.POST)
    public Object exportPayment(PropertyAccountGetDTO propertyAccountGetDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyAccountGetDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyAccountGetDTO.class, request);
            if(StringUtils.isBlank(propertyAccountGetDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            Path excelFilePath = Paths.get(PROJECT_STATIC_FILE_PATH, PlatformConstants.PAYMENT_EXORT_EXPORT_FILE);
            if (!new File(excelFilePath.toString()).exists()) {  //模板文件不存在
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_TMPLATE_FILE_PATH_NOT_EXISTS_ERR.getErrorCode());
            }
            List<PropertyPaymentVO> result =
                    iPropertyAccountServiceClient.getPaymentByFeeIds(propertyAccountGetDTO);
            //创建Excel操作对象，07之前版本(*.xls)使用HSSFWorkBook 07之后版本使用（*.xlsx）XSSFWorkbook
            try (InputStream excelFileStream = new FileInputStream(excelFilePath.toString())) {

                try (HSSFWorkbook workbook = new HSSFWorkbook(excelFileStream)) {
                    HSSFSheet sheet = workbook.getSheetAt(0);
                    short rowHeght = 420;
                    //移除模板中可能存在的样例数据
                    for (int rowIndex = 1; rowIndex <= 3; rowIndex++) {
                        HSSFRow row = sheet.getRow(rowIndex);
                        if (row != null) {
                            rowHeght = row.getHeight();
                            sheet.removeRow(row);
                        }
                    }

                    for (int index = 0; index < result.size(); index++) {
                        PropertyPaymentVO propertyPaymentVO = result.get(index);
                        int rowIndex = index + 1; //标题行
                        HSSFRow dataRow = sheet.createRow(rowIndex);
                        dataRow.setHeight(rowHeght);
                        HSSFCell noteCell = dataRow.createCell(0);
                        noteCell.setCellValue(propertyPaymentVO.getFeeId());
                        noteCell = dataRow.createCell(1);
                        noteCell.setCellValue(propertyPaymentVO.getMonth());
                        noteCell = dataRow.createCell(2);
                        noteCell.setCellValue(propertyPaymentVO.getFeeNumber());
                        noteCell = dataRow.createCell(3);
                        noteCell.setCellValue(propertyPaymentVO.getAddress());
                        noteCell = dataRow.createCell(4);
                        noteCell.setCellValue(propertyPaymentVO.getRealName());
                        noteCell = dataRow.createCell(5);
                        noteCell.setCellValue(propertyPaymentVO.getPhoneNum());
                        noteCell = dataRow.createCell(6);
                        noteCell.setCellValue(BillTypeEnum.getDescription(Integer.parseInt(propertyPaymentVO.getType())));
                        noteCell = dataRow.createCell(7);
                        noteCell.setCellValue(propertyPaymentVO.getDueAmount());
                        noteCell = dataRow.createCell(8);
                        noteCell.setCellValue(propertyPaymentVO.getPenalty());
                        noteCell = dataRow.createCell(9);
                        noteCell.setCellValue(propertyPaymentVO.getPaidAmount());
                        noteCell = dataRow.createCell(10);
                        noteCell.setCellValue("0".equals(propertyPaymentVO.getPaymentCount())?"":propertyPaymentVO.getPaymentCount());
                        noteCell = dataRow.createCell(11);
                        noteCell.setCellValue(OriginPayEnum.getDescription(Integer.parseInt(propertyPaymentVO.getOriginPay())));
                        noteCell = dataRow.createCell(12);
                        noteCell.setCellValue(PaymentTypeEnum.getDescription(Integer.parseInt(propertyPaymentVO.getPaymentType())));
                        noteCell = dataRow.createCell(13);
                        noteCell.setCellValue(propertyPaymentVO.getOperateName());
                        noteCell = dataRow.createCell(14);
                        noteCell.setCellValue(propertyPaymentVO.getPayTime());

                        //Excel格式保护密码
//                        sheet.protectSheet("itlong");
                    }
                    String fileName = String.format("%s_PaymentInfo_%s.xls",
                            propertyAccountGetDTO.getProjectId(),
                            DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS"));
                    fileName = URLEncoder.encode(fileName, "UTF-8");

                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    workbook.write(os);
                    byte[] content = os.toByteArray();
                    InputStream exportFileStream = new ByteArrayInputStream(content);
                    String exportfileUrl = uploadFile(exportFileStream,fileName);
                    if (StringUtils.isBlank(exportfileUrl)){
                        return new MessageVO(PropertyErrorCodeEnum.PROJECT_EXPORT_FILE_SAVE_ERR.getErrorCode());
                    }
                    return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), (Object) exportfileUrl);
                }
            }
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_收费管理_导出已缴费账单】导出已缴费账单失败"), e);
        }
    }

    /**
     * <desc>
     *      发送短信
     * <desc/>
     *
     * @param messageInfo 月份+电话号(json数组)
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/14
     */
    @ResponseBody
    @AuthAccessRequired
    @RequestMapping(path = "/sendMessage", method = RequestMethod.POST)
    public Object sendMessage(String messageInfo,String projectId,String loginUserId) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            messageInfo = request.getAttribute("messageInfo") == null ? null : request.getAttribute("messageInfo").toString();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            loginUserId = request.getAttribute("loginUserId") == null ? null : request.getAttribute("loginUserId").toString();
            if(StringUtils.isBlank(projectId)) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            if(StringUtils.isBlank(messageInfo)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_MESSAGE_INFO_EMPTY_ERR.getErrorCode());
            }
            OperatePropertyAccountDetailVO detailVO = iOperatePropertyAccountServiceClient.getDetail(loginUserId);
            JSONArray json = JSONArray.parseArray(messageInfo);
            for(int i=0;i<json.size();i++){
                // 遍历 jsonarray 数组，把每一个对象转成 json 对象
                JSONObject job = json.getJSONObject(i);
                String feeId = job.get("feeId").toString();
                String month = job.get("month").toString();
                String phoneNum = job.get("phoneNum").toString();
                String[] date = month.split("-");
                String content = "";
                String day = "";
                if ("1".equals(job.get("type").toString())) {//抄表费
                    //获取收费规则最早收费日
                    day = iPropertyRuleServiceClient.getMinFeeDay(feeId);
                }else {
                    PropertyAccountGetDTO propertyAccountGetDTO = new PropertyAccountGetDTO();
                    propertyAccountGetDTO.setFeeIds(feeId);
                    propertyAccountGetDTO.setProjectId(projectId);
                    List<PropertyUnpaymentVO> list = iPropertyAccountServiceClient.getUnpaymentByFeeIds(propertyAccountGetDTO);
                    day = list.get(0).getCreateTime();
                    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Date mindate = sf.parse(day);
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(mindate);
                    day = calendar.get(Calendar.DAY_OF_MONTH)+"";
                }
                if (date.length >= 2) {
                    content = "贵户于" + date[0].replace(".","年") + "月-" + date[1].replace(".","年") + "月的";
                } else {
                    content = "贵户于" + date[0].replace(".","年") + "月的";
                }
                content = content + BillTypeEnum.getDescription(Integer.parseInt(job.get("type").toString())) + "为" + job.get("paidAmount").toString() +
                          "元 还未缴纳，请您于"+day+"日前缴纳避免产生滞纳金，如您不便请致电物业上门收取或下载手机App【云半径】进行缴费 (" + detailVO.getPropertyName() + ")";
                iIotTpSmsServiceClient.sendSmsCodeByPhone(phoneNum,content);
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), "");
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_收费管理_发送短信】发送短信失败"), e);
        }
    }

    /**
     * <desc>
     *      查看缴费账单明细
     * <desc/>
     *
     * @param feeId 缴费账单ID
     * @param projectId 项目编号
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/15
     */
    @ResponseBody
    @AuthAccessRequired
    @RequestMapping(path = "/getAccountDetail", method = RequestMethod.POST)
    public Object getAccountDetail(String feeId, String projectId) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            feeId = request.getAttribute("feeId") == null ? null : request.getAttribute("feeId").toString();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            if(StringUtils.isBlank(projectId)) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            if(StringUtils.isBlank(feeId)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_FEEID_EMPTY_ERR.getErrorCode());
            }
            PropertyAccountDetailVO result =
                    iPropertyAccountServiceClient.getAccountDetail(feeId,projectId);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), result);
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_收费管理_查看缴费账单明细】查看缴费账单明细失败"), e);
        }
    }

    /**
     * <desc>
     *      收款
     * <desc/>
     *
     * @param feeId 缴费账单ID
     * @param projectId 项目编号
     * @param paymentType 收费方式：1现金 2银行转账 3支付宝转账 4微信转账 5小区收款码-微信 6小区收款码-支付宝 7其他支付方式
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/15
     */
    @RequestMapping(path = "/payment", method = RequestMethod.POST)
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.ACCOUNT_PAYMENT_LOG_DESC)
    @ResponseBody
    public Object payment(String feeId, String projectId, String paymentType,String loginUserId, String token) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            feeId = request.getAttribute("feeId") == null ? null : request.getAttribute("feeId").toString();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            paymentType = request.getAttribute("paymentType") == null ? null : request.getAttribute("paymentType").toString();
            loginUserId = request.getAttribute("loginUserId") == null ? null : request.getAttribute("loginUserId").toString();
            token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
            if(StringUtils.isBlank(projectId)) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            if(StringUtils.isBlank(feeId)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_FEEID_EMPTY_ERR.getErrorCode());
            }
            if(StringUtils.isBlank(paymentType)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_PAYMENTTYPE_EMPTY_ERR.getErrorCode());
            }
            String feeStatus =
                    iPropertyAccountServiceClient.getFeeStatus(feeId,projectId);
            if (feeStatus == null) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_ACCOUNT_IS_NULL_ERR.getErrorCode());
            }
            if ("2".equals(feeStatus)) {
                return new MessageVO(PropertyErrorCodeEnum.PROJECT_ACCOUNT_IS_PAYMENT_ERR.getErrorCode());
            }
            List<AppUserAndRoomInfoVO> list = iPropertyAccountServiceClient.payment(feeId,projectId,paymentType,loginUserId);
            StringBuilder roomIds = new StringBuilder();
            if(list != null && !list.isEmpty()){
                Map<String,String> comands = new HashMap<>();
                comands.put("refreshSips","1");
                for(AppUserAndRoomInfoVO roomInfoVO : list){
                    iIotTpJPushClientServiceClient.pushWithTaskTO(roomInfoVO.getProjectId(),roomInfoVO.getPhoneNum(),comands,"已缴费取消欠费联动app功能限制");
                    if (roomIds.length() == 0) {
                        roomIds.append(roomInfoVO.getRoomId());
                    } else {
                        roomIds.append(",").append(roomInfoVO.getRoomId());
                    }
                }

            }
            if (roomIds.length() != 0) {
                PadFaceSyncDataDTO padFaceSyncDataDTO = new PadFaceSyncDataDTO();
                padFaceSyncDataDTO.setOperateType("0");
                padFaceSyncDataDTO.setRoomId(roomIds.toString());
                padFaceSyncDataDTO.setProjectId(projectId);
                padFaceSyncDataDTO.setSourceSystem(2);
                iPadFaceSyncDataServiceClient.userOrFloorSync(padFaceSyncDataDTO);
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), "");
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_收费管理_账单收款】账单收款失败"), e);
        }
    }

    /**
     * <desc>
     *    Ftp上传文件，返回Url.
     * </desc>
     *
     * @param inputStream 文件流
     * @return 文件上传成功后会返回Url,否则返回空
     * @author Qiang.S
     * @createDate 2018-08-14
     */
    public String uploadFile(InputStream inputStream, String fileName) throws IOException {

        String fileUrl = "";
        String fileType = StringHandlerUtil.copySubStr(fileName, fileName.lastIndexOf('.'), fileName.length());
        UploadFileUtil.UploadFile uploadFileUtil = new UploadFileUtil().new UploadFile(
                FILE_FTP_HOST,
                FILE_FTP_USERNAME,
                FILE_FTP_PASSWORD,
                FILE_FTP_PORT,
                inputStream,
                fileType,
                FILE_ACCESS_URL,
                FileCatalogEnum.ACCOUNTTEMPLATE_FILE.getType()
        );
        Map<String, Object> resultMap = UploadFileUtil.uploadFile(uploadFileUtil);
        Boolean returnCode = (Boolean)resultMap.get("returnCode");
        if (returnCode == false){
            return fileUrl;
        }
        fileUrl = resultMap.get("accessPath").toString();
        return fileUrl;
    }

}